#include "CCallFuncInterval.h"

CCallFuncInterval* CCallFuncInterval::actionWithDuration(float duration, SEL_SCHEDULE selector)
{
	return CCallFuncInterval::create(duration, selector);
}

CCallFuncInterval* CCallFuncInterval::create(float duration, SEL_SCHEDULE selector)
{
	CCallFuncInterval *pCallFuncInterval = new CCallFuncInterval();
	pCallFuncInterval->initWithDuration(duration, selector);
	pCallFuncInterval->autorelease();

	return pCallFuncInterval;
}

bool CCallFuncInterval::initWithDuration(float duration, SEL_SCHEDULE selector)
{
	if (CCActionInterval::initWithDuration(duration))
	{
		m_selector = selector;
		return true;
	}

	return false;
}

CCObject* CCallFuncInterval::copyWithZone(CCZone *pZone)
{
	CCZone* pNewZone = NULL;
	CCallFuncInterval* pCopy = NULL;
	if(pZone && pZone->m_pCopyObject) 
	{
		//in case of being called at sub class
		pCopy = (CCallFuncInterval*)(pZone->m_pCopyObject);
	}
	else
	{
		pCopy = new CCallFuncInterval();
		pZone = pNewZone = new CCZone(pCopy);
	}

	CCActionInterval::copyWithZone(pZone);

	pCopy->initWithDuration(m_fDuration, m_selector);

	CC_SAFE_DELETE(pNewZone);
	return pCopy;
}

void CCallFuncInterval::startWithTarget(CCNode *pTarget)
{
	CCActionInterval::startWithTarget(pTarget);
}

void CCallFuncInterval::update(float time)
{
	if (m_pTarget)
	{
		(m_pTarget->*m_selector)(time);
	}
}